package com.laan.plat;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;

public class LaanGame extends Activity {
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game);
        
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
		GV.Screen.wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GameOnLock");
        
        GV.Instancies.laangamesv = (LaanGameSV) findViewById(R.id.game_surface);
        GV.Instancies.laangame = this;
        
//        ((ImageButton) findViewById(R.id.game_left)).setClickable(false);
//        ((ImageButton) findViewById(R.id.game_right)).setClickable(false);
////        
//        RelativeLayout lay_arrows = (RelativeLayout) findViewById(R.id.game_arrows);
//        
//        lay_arrows.setOnTouchListener(new View.OnTouchListener() {
//			@Override
//			public boolean onTouch(View v, MotionEvent e) {
////				Log.i("Arrows", String.valueOf(e.getActionMasked()));
////				GV.Instancies.laangamesv.canJump = false;
//				int actInd = e.getActionIndex();
//				
////				if(e.getActionMasked() == MotionEvent.ACTION_UP) {
////					GV.Instancies.laangamesv.hasMoved = true;
////				}
//				GV.Instancies.laangamesv.dispatchTouchEvent(e);
//				
//				
//				if(e.getPointerId(actInd) == 1) Log.i("arrowtouchin", String.valueOf(e.getActionMasked()));
//				if(e.getPointerId(actInd) == 1) Log.i("touch", String.valueOf(e.getPointerId(actInd)));
//				
////				if(e.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
////					return GV.Instancies.laangamesv.dispatchTouchEvent(e);
////				}
//				
//				boolean moveRight = false;
//				Rect btn_bounds = new Rect();
//				getWindow().findViewById(R.id.game_left).getHitRect(btn_bounds);
//				boolean moveLeft = btn_bounds.contains((int)e.getX(actInd), (int)e.getY(actInd)) && e.getActionMasked() != MotionEvent.ACTION_UP;
////				boolean move = e.getActionMasked() == MotionEvent.ACTION_DOWN || e.getActionMasked() == MotionEvent.ACTION_MOVE;
//				if(moveLeft) {
//					if(e.getPointerId(actInd) == 1) Log.i("moveleft", String.valueOf(e.getPointerId(actInd)));
//					GV.Game.prota.moveLeft();
////					((ImageButton) getWindow().findViewById(R.id.game_left)).performClick();
//				}
//				else {
//					if(e.getPointerId(actInd) == 1) Log.i("moveright", String.valueOf(e.getPointerId(actInd)));
//					getWindow().findViewById(R.id.game_right).getHitRect(btn_bounds);
//					moveRight = btn_bounds.contains((int)e.getX(actInd), (int)e.getY(actInd)) && e.getActionMasked() != MotionEvent.ACTION_UP;
//					if(moveRight) GV.Game.prota.moveRight();
////					else return GV.Instancies.laangamesv.dispatchTouchEvent(e);
//				}
//				return true;
//			}
//		});
		
//		ImageButton btn_right = (ImageButton) findViewById(R.id.game_right);
//		btn_right.setOnTouchListener(new ImageButton.OnTouchListener() {
//			@Override
//			public boolean onTouch(View v, MotionEvent e) {
////				if(e.getActionMasked() != MotionEvent.ACTION_UP)
////					GV.Instancies.laangamesv.prota.moveRight();
////				GV.Instancies.laangamesv.dispatchTouchEvent(e);
//				RelativeLayout lay_arrows = (RelativeLayout) findViewById(R.id.game_arrows);
//				lay_arrows.dispatchTouchEvent(e);
//				return false;
//			}
//		});
//		
//		ImageButton btn_left = (ImageButton) findViewById(R.id.game_left);
//		btn_left.setOnTouchListener(new ImageButton.OnTouchListener() {
//			@Override
//			public boolean onTouch(View v, MotionEvent e) {
////				if(e.getActionMasked() != MotionEvent.ACTION_UP)
////					GV.Instancies.laangamesv.prota.moveLeft();
////				GV.Instancies.laangamesv.dispatchTouchEvent(e);
//				return false;
//			}
//		});
	}

	@Override
	protected void onPause() {
		GV.Instancies.laangamesv.stopthread();
		GV.Screen.wl.release();
		super.onPause();
	}

	@Override
	protected void onResume() {
		GV.Instancies.laangamesv.startthread();
		GV.Screen.wl.acquire();
		super.onResume();
	}
	
	@Override
	public void onBackPressed() {
		finish();
		//activity transition animation
		super.onBackPressed();
	}
}